#include "Quadrature.h"

using namespace std;

void TriangularQuad::ReadQuadInfo(const std::string& file_name, size_t _acc)
{
    std::ifstream is(file_name);  
    char text[64];
    size_t n_tbl, n_qpoints, acc, next_acc;
    is >> n_tbl;
    if (n_tbl < _acc) {
		std::cerr << "The required algebraic accuracy " << _acc
		  << " is too high,"
		  << " and the actual algebraic accuracy is "
		  << n_tbl << std::endl;;
		acc = n_tbl;
    } else
		acc = _acc;
    do {
		is >> next_acc;
		if (next_acc >= acc) {
			is >> n_qpoints;
			Quadrature<2>::quad_points.resize(n_qpoints);
			Quadrature<2>::quad_weights.resize(n_qpoints);
			for (size_t i = 0; i < n_qpoints; i++) {
				double x, y, w;
				is >> x >> y >> w;
				Quadrature<2>::quad_points[i][0] = x;
				Quadrature<2>::quad_points[i][1] = y;
				Quadrature<2>::quad_weights[i] = w;
			}
			Quadrature<2>::accuracy = acc;
			break;
		} else {
			is >> n_qpoints;
			for (size_t i = 0; i < n_qpoints; i++)
				is.getline(text, 64);
			is.getline(text, 64);
		}
    } while (1);
	Quadrature<2>::quad_weights *= 0.5;
}


